import { ethers } from 'ethers';
import { defineStore } from 'pinia'
import { ref } from 'vue';
import { IUserInfo } from '@/model/user';
import { useI18n } from "vue-i18n";
import { i18n } from "@/lang";

export const userStore = defineStore('user',
  () => {
    const { t } = useI18n();

    const address = ref("");
    const sign = ref("");
    const info = ref({
      user: {
        isNode: undefined,
        code: "",
        inviteCode: "",
        address: "",
        parentAddress: "",
      }
    })


    const menuList = computed(() => {
      return [
        {
          key: "1",
          menuName: t("menu1"),
          isShow: true,
          children: [
            {
              key: "1-1",
              menuName: t("menu1_1"),
              path: "/about-us",
              icon: "icon-shouye"
            },
            {
              key: "1-1",
              menuName: t("menu1_2"),
              path: "/z-plan",
              icon: "icon-z"
            }
          ]
        },
        {
          key: "2",
          menuName: t("menu2"),
          isShow: false,
          children: [
            {
              key: "2-1",
              menuName: t("menu2_1"),
              path: "/assets",
              icon: "icon-a-bitcoinbitebi"
            },
            {
              key: "2-2",
              menuName: t("menu2_2"),
              path: "/pledge",
              icon: "icon-zichan-quanbushebei"
            },
            {
              key: "2-2",
              menuName: t("nodeApplication"),
              path: "/nodeApplication",
              icon: "icon-jiedianshenqing"
            }
          ]
        },
        {
          key: "3",
          menuName: t("menu3"),
          isShow: false,
          children: [
            {
              key: "3-1",
              menuName: t("menu3_1"),
              path: "/invitation",
              icon: "icon-zhuceyaoqing"
            },
            {
              key: "3-2",
              menuName: t("menu3_2"),
              path: "/community",
              icon: "icon-zhaoshangdailifenlei"
            },
            {
              key: "3-3",
              menuName: t("menu3_3"),
              path: "/ecology",
              icon: "icon-shengtaiquan"
            }
          ]
        },
        {
          key: "4",
          menuName: t("menu4"),
          isShow: false,
          children: [
            {
              key: "4-1",
              menuName: t("menu4_1"),
              path: "/invitation",
              icon: "icon-link",
              url: "https://avedex.cc/token/0x9F90C5cd1418c4D2Ab733d7335498149C5b14169-bsc?from=Default"
            },
            // {
            //   key: "4-2",
            //   menuName: t("menu4_2"),
            //   path: "/community",
            //   icon: "icon-link",
            //   url: "https://longswap.app/swap?utm_source=tokenpocket"
            // }
          ]
        }
      ];
    });
    function updateAddress(newVal) {
      // address.value = '0xa3aA89B7313C0A9698FEDc1Cf240335c92c2083e' || ethers.getAddress(newVal);
      // address.value = '0x5276005B39264287c805924c89861C1Cc95473DC' || ethers.getAddress(newVal);
      // address.value = '0x6Ef5583903e6E83211c47c236A7B57D2F9373647' || ethers.getAddress(newVal);//顶号
      // 这个号0xB81bFdDb5A5d0b9c67ABC1E3a3058459dF7A506c的前端邀请人前端显示成固定的  0x9A7a567E1937333557E6BF894A71e419d4481244 这个地址显示
      // address.value = '0xB81bFdDb5A5d0b9c67ABC1E3a3058459dF7A506c' || ethers.getAddress(newVal);
      address.value = ethers.getAddress(newVal);
    }
    function updateSign(newVal) {
      sign.value = newVal;
    }
    function updateInfo(newVal: IUserInfo) {
      info.value = newVal;
    }
    return { address, sign, info, menuList, updateAddress, updateSign, updateInfo }
  }, {
  persist: {
    storage: sessionStorage,
  },
}
)

